package JAVA300.第十一章多线程;

/**
 * 阻塞状态 join
 * 程序故事：爸爸要抽烟发现烟完了 让儿子去买烟
 */

public class thread_11_threadState_blocked_join1 {
    public static void main(String[] args) throws InterruptedException {
        new Thread(new Father()).start();

    }
}

class Father extends Thread{
    @Override
    public void run() {
        System.out.println("dad wants  cigar");
        System.out.println("call son。。。。");
        //插队线程 避免各走各的 烟还没到 钱先到了
        Thread thread = new Thread(new Son());
        thread.start();

        try {
            thread.join(50000);//father block
        } catch (InterruptedException e) {
            e.printStackTrace();
            System.out.println("son not back" );
        }

        System.out.println("give money");

    }
}

class Son extends Thread{
    @Override
    public void run() {
        System.out.println("go to buy cigar");
        System.out.println("meet a friend, talk 10s");
        for (int i=0;i<10;i++){
            try {

                Son.sleep(1000);
                System.out.println("talk "+(i+1)+"s" );

            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
        System.out.println("get cigar back home");




    }

}
